//
//  SSWEPhoneLoginViewController.m
//  ssweapp
//
//  Created by sfit on 2018/4/24.
//  Copyright © 2018年 sfit. All rights reserved.
//
#import "MessageLoginView.h"
#import "TradeLoginView.h"
#import "SSWEPhoneLoginViewController.h"
#import "SSWETraderApiWrapper.h"
#import "SSWEMdApiWrapper.h"

#import "SFITUITabBarViewController.h"
//#import "SSWEMobileLoginViewController.h"
#import "SSWERegisterViewController.h"
#import "SSWEPhoneLoginViewController.h"
#import "SSWENewlyListingViewController.h"
#import "SSWETradeMainViewController.h"
#import "SSWESettingViewController.h"
#import "SSWEMarketMainViewController.h"
#import "SSWEOCShfeFtdcRspUserLoginField.h"
#import "SSWEOCShfeFtdcRspValidateCodeField.h"

#import "SSWEOCShfeFtdcRspInfoField.h"
#import "SSWEFoggetPWDViewController.h"
#import "SFITUILetterNumPadView.h"
#import "SSWEInfoMainViewController.h"

@interface SSWEPhoneLoginViewController ()<tradeLoginDelegate>

@property (nonatomic ,strong)UIView *headerView;
@property (nonatomic ,strong)UIView *bottomView;
@property (nonatomic ,strong)MessageLoginView *messageLoginView;

@property (nonatomic ,strong)TradeLoginView *tradeLoginView;
@property (nonatomic ,strong)UIButton *temButton;
@property (nonatomic ,strong)UIButton *tradeLoginBtn;
@property (nonatomic ,strong)UIButton *messageLoginBtn;
@property (nonatomic ,strong)UILabel *centerLabel;
@property (nonatomic,strong) CAShapeLayer *arrowLayer;
@property (nonatomic,strong)NSString *countStr;
@property (nonatomic ,strong)UIWebView *web;
@property (nonatomic ,strong)NSString *traderFrontConnectedStr;
@property (nonatomic ,strong)NSString *mdFrontConnectedStr;

@property (strong, nonatomic) SFITUILetterNumPadView *letterNumPadView;
@property (nonatomic,strong)UIAlertController *alertController;

@property (nonatomic ,strong)UIView *messageLoginView2;
@property (nonatomic ,strong)UITextField *phoneNumTextField;
//@property (nonatomic ,strong)UITextField *

@end

////交易前置机连接状态
//@property (nonatomic, assign) BOOL TraderFrontConnected;
////行情前置机连接状态
//@property (nonatomic, assign) BOOL MdFrontConnected;

@implementation SSWEPhoneLoginViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    
    if ([self.countStr isEqualToString:@"9"]) {
        
        [self  tradeNextNumAction];
    }
    
    if (SSWE_GLOBAL.TraderFrontConnected == YES && SSWE_GLOBAL.MdFrontConnected == YES) {
        
        self.tradeLoginView.statusLabel.text = @"已连接";
        self.tradeLoginView.statusLabel.textColor = [UIColor greenColor];
        
        
    }else
    {
        self.tradeLoginView.statusLabel.text = @"正在尝试连接服务器...";
        self.tradeLoginView.statusLabel.textColor = [UIColor redColor];
    }
    
    [[SSWETraderApiWrapper sharedManager] RegFrontConnectedEventForClassName:NSStringFromClass([self class]) callback:^(id bizRspInfo, id resultInfo, int requestId, bool isLast, bool isError) {
        
        [self  tradeNextNumAction];
        
        
    }];
    if (SSWE_GLOBAL.isFirstCreated) {
        
        SSWE_GLOBAL.isFirstCreated = NO;
        [[SSWETraderApiWrapper sharedManager] preheat];
        [[SSWEMdApiWrapper sharedManager] preheat];
    } else {
        [[SSWEMdApiWrapper sharedManager] PauseReactor];
        [[SSWETraderApiWrapper sharedManager] PauseReactor];
        [[SSWETraderApiWrapper sharedManager] preheat];
        [[SSWEMdApiWrapper sharedManager] preheat];
        [[SSWETraderApiWrapper sharedManager] setup];
        [[SSWEMdApiWrapper sharedManager] setup];
    }
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *pwd = [user objectForKey:@"password"];
    NSString *userNameStr = [user objectForKey:@"userName"];
    
    self.tradeLoginView.useridTextField.text = userNameStr;
    self.tradeLoginView.pwdTextField.text = pwd;
    
    SSWE_GLOBAL.appLaunched = YES;
}
-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
}

- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    
    if (self.tradeLoginBtn.selected == YES) {
        
        [self.arrowLayer removeFromSuperlayer];
        self.arrowLayer.position = CGPointMake(self.tradeLoginBtn.frame.size.width/2, self.tradeLoginBtn.frame.size.height - 3);
        [self.tradeLoginBtn.layer addSublayer:self.arrowLayer];
    }
    
    if (self.messageLoginBtn.selected == YES) {
        [self.arrowLayer removeFromSuperlayer];
        self.arrowLayer.position = CGPointMake(self.messageLoginBtn.frame.size.width/2, self.messageLoginBtn.frame.size.height - 3);
        [self.messageLoginBtn.layer addSublayer:self.arrowLayer];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [SSWE_GLOBAL addObserver:self forKeyPath:@"TraderFrontConnected" options:NSKeyValueObservingOptionNew context:nil];
    [SSWE_GLOBAL addObserver:self forKeyPath:@"MdFrontConnected" options:NSKeyValueObservingOptionNew context:nil];
    self.traderFrontConnectedStr = @"0";
    self.mdFrontConnectedStr = @"0";
    
    //SSWE_GLOBAL.isFirstCreated = YES;
    weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        __weak_self__.web = [[UIWebView alloc] initWithFrame:CGRectZero];
        [__weak_self__.view addSubview:__weak_self__.web];
    });
    
    self.letterNumPadView = [SFITUILetterNumPadView new];
    self.tradeLoginView.pwdTextField.inputView = self.letterNumPadView;
    self.letterNumPadView.inputSource = self.self.tradeLoginView.pwdTextField;
    
    self.countStr = @"9";
    self.tradeLoginView.pwdTextField.secureTextEntry = YES;
    [self.view addSubview:self.headerView];
    [self.view addSubview:self.bottomView];
    
    [self.headerView addSubview:self.tradeLoginBtn];
    [self.headerView addSubview:self.messageLoginBtn];
    [self.headerView addSubview:self.centerLabel];
    [self.view addSubview:self.tradeLoginView];
    [self drawArrowLayer];
    self.tradeLoginBtn.selected = YES;
    
    [self.centerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(2);
        make.centerX.mas_equalTo(self.headerView.centerX);
        make.bottom.equalTo(self.headerView.bottom).offset(-18);
        
    }];
    
    [self.tradeLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(100);
        make.left.mas_equalTo(15);
        make.right.equalTo(self.centerLabel.left).offset(-10);
        make.bottom.equalTo(self.headerView.bottom);
        
    }];
    
    [self.messageLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(100);
        make.left.equalTo(self.centerLabel.right).offset(10);
        make.right.mas_equalTo(-15);
        make.bottom.equalTo(self.headerView.bottom);
        
    }];
    
    [self.tradeLoginView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.headerView.bottom);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(SCREEN_WIDTH);
        make.bottom.equalTo(self.bottomView.top);
        
    }];
    //
    //        [self.view addSubview:self.messageLoginView];
    //        [self.messageLoginView mas_makeConstraints:^(MASConstraintMaker *make) {
    //            make.top.equalTo(self.headerView.bottom);
    //            make.left.mas_equalTo(0);
    //            make.right.equalTo(SCREEN_WIDTH);
    //            make.bottom.equalTo(self.bottomView.top);
    //        }];
    
    
    
}

#pragma mark ---  private method

- (void)drawArrowLayer{
    self.arrowLayer = [[CAShapeLayer alloc] init];
    self.arrowLayer.bounds = CGRectMake(0, 0, 14, 7);
    [self.arrowLayer setFillColor:[UIColor whiteColor].CGColor];
    UIBezierPath *arrowPath = [UIBezierPath bezierPath];
    [arrowPath moveToPoint:CGPointMake(7,0)];
    [arrowPath addLineToPoint:CGPointMake(14, 7)];
    [arrowPath addLineToPoint:CGPointMake(0, 7)];
    [arrowPath closePath];
    self.arrowLayer.path = arrowPath.CGPath;
}

//观察网络是否连接成功
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void *)context{
    
    if ([keyPath isEqualToString:@"TraderFrontConnected"]) {
        
        if (change[@"new"]) {
            
            NSString *traderFrontConnectedStr = change[@"new"];
            self.traderFrontConnectedStr = traderFrontConnectedStr;
            
        }
    }
    if ([keyPath isEqualToString:@"MdFrontConnected"])
    {
        if (change[@"new"]) {
            
            NSString *MdFrontConnectedStr = change[@"new"];
            self.mdFrontConnectedStr = MdFrontConnectedStr;
        }
    }
    
    NSInteger tradenUM = [self.traderFrontConnectedStr integerValue];
    NSInteger mdUM = [self.mdFrontConnectedStr integerValue];
    
    if (tradenUM == 1 && mdUM == 1) {
        dispatch_async(dispatch_get_main_queue(), ^{
            
            self.tradeLoginView.statusLabel.text = @"已连接";
            self.tradeLoginView.statusLabel.textColor = [UIColor greenColor];
        });
    }else
    {
        dispatch_async(dispatch_get_main_queue(), ^{
            self.tradeLoginView.statusLabel.text = @"正在尝试连接服务器...";
            self.tradeLoginView.statusLabel.textColor = [UIColor redColor];
        });
    }
    //    if ([self.traderFrontConnectedStr isEqualToString:@"1"] && [self.mdFrontConnectedStr isEqualToString:@"1"]) {
    //        self.tradeLoginView.statusLabel.text = @"已连接";
    //        self.tradeLoginView.statusLabel.textColor = [UIColor greenColor];
    //
    //    }else
    //    {
    //        self.tradeLoginView.statusLabel.text = @"正在尝试连接服务器...";
    //        self.tradeLoginView.statusLabel.textColor = [UIColor redColor];
    //    }
    
}


#pragma mark --  tradeLoginDelegate

- (void)tradeLoginAction
{
    weakify(self)
    
    __block NSString *userName = __weak_self__.tradeLoginView.useridTextField.text;
    __block NSString *pwd = __weak_self__.tradeLoginView.pwdTextField.text;
    __block NSString *vcode =__weak_self__.tradeLoginView.verifyTextField.text;
    
    if (userName == nil|| [userName isEqualToString:@""]) {
        
        __weak_self__.alertController = [UIAlertController alertControllerWithTitle:@"用户代码不能为空" message:nil preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [__weak_self__ dismissViewControllerAnimated:__weak_self__.alertController completion:nil];
            
        }];
        
        [__weak_self__.alertController addAction:okAction];
        [__weak_self__ presentViewController:__weak_self__.alertController animated:YES completion:nil];
        
    }else if (pwd == nil || [pwd isEqualToString:@""] ) {
        
        __weak_self__.alertController = [UIAlertController alertControllerWithTitle:@"密码不能为空" message:nil preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [__weak_self__ dismissViewControllerAnimated:__weak_self__.alertController completion:nil];
            
        }];
        
        [__weak_self__.alertController addAction:okAction];
        [__weak_self__ presentViewController:__weak_self__.alertController animated:YES completion:nil];
        
    }else  if (vcode == nil || [vcode isEqualToString:@""]) {
        
        __weak_self__.alertController = [UIAlertController alertControllerWithTitle:@"验证码不能为空" message:nil preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [__weak_self__ dismissViewControllerAnimated:YES completion:nil];
            
        }];
        
        [__weak_self__.alertController addAction:okAction];
        [__weak_self__ presentViewController:__weak_self__.alertController animated:YES completion:nil];
        
    }else
    {
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        [user setObject:userName forKey:@"userName"];
        [user setObject:pwd forKey:@"password"];
        NSDictionary *paraDic0 = @{@"username": userName,@"password" :pwd};
        
        [[SSWEMdApiWrapper sharedManager] ReqUserLogin:paraDic0 Callback:^(id bizRspInfo, id resultInfo, int requestId, bool isLast, bool isError){
            SSWEOCShfeFtdcRspUserLoginField *mdField = (SSWEOCShfeFtdcRspUserLoginField *)bizRspInfo;
            SSWEOCShfeFtdcRspInfoField *resultField = (SSWEOCShfeFtdcRspInfoField *)resultInfo;
            if (resultField.ErrorID == 0) {
                DDLogDebug(@"登录成功");
                SSWE_GLOBAL.userID = mdField.UserID;
                SSWE_GLOBAL.participantID = mdField.EntityID;
                SSWE_GLOBAL.mdSessionId = mdField.SessionID;
                
                //
                NSDictionary *paraDic = @{@"username": userName,@"password" :pwd,@"vcode" : vcode};
                [[SSWETraderApiWrapper sharedManager] ReqUserLogin:paraDic Callback:^(id bizRspInfo, id resultInfo, int requestId, bool isLast, bool isError) {
                    
                    SSWEOCShfeFtdcRspUserLoginField *field = (SSWEOCShfeFtdcRspUserLoginField *)bizRspInfo;
                    SSWEOCShfeFtdcRspInfoField *resultField = (SSWEOCShfeFtdcRspInfoField *)resultInfo;
                    
                    SSWE_GLOBAL.localListID = [field.MaxListLocalID intValue];
                    SSWE_GLOBAL.localDelistID = [field.MaxDelistLocalID intValue];
                    SSWE_GLOBAL.participantID = field.EntityID;
                    
                    if (resultField.ErrorID == 0) {
                        DDLogDebug(@"登录成功");
                        //存储登录成功数据
                        [SSWEGlobalVars sharedInstance].userIsLogin = YES;
                        [SSWEGlobalVars sharedInstance].tradingDay = field.TradingDay;
                        [SSWEGlobalVars sharedInstance].traderSessionId = field.SessionID;
                        dispatch_async(dispatch_get_main_queue(), ^{
                            
                            if (__weak_self__.tradeLoginBtn.selected == YES) {
                                
                                [SSWEGlobalVars sharedInstance].userType = YES;
                                
                            }else
                            {
                                [SSWEGlobalVars sharedInstance].userType = NO;
                            }
                            
                            UIWindow *window = [UIApplication sharedApplication].keyWindow;
                            SFITUITabBarViewController *baseController = [SFITUITabBarViewController sharedTabbarController];
                            baseController.selectedIndex = 3;
                            [baseController setNavRootViewControllers:@[[SSWEInfoMainViewController new], //资讯
                                                                        [[SSWEMarketMainViewController alloc]init], //行情
                                                                        [[SSWENewlyListingViewController alloc] init],
                                                                        [[SSWETradeMainViewController alloc] init], //交易
                                                                        [[SSWESettingViewController alloc] init] //设置
                                                                        ]];
                            window.rootViewController = baseController;
                        });
                        
                    } else {
                        
                        dispatch_async(dispatch_get_main_queue(), ^{
                            
                            NSString *errorMessage = resultField.ErrorMsg;
                            __weak_self__.alertController = [UIAlertController alertControllerWithTitle:errorMessage message:nil preferredStyle:UIAlertControllerStyleAlert];
                            
                            UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                
                                [ __weak_self__ tradeNextNumAction];
                                [__weak_self__ dismissViewControllerAnimated:__weak_self__.alertController completion:nil];
                                
                            }];
                            
                            [__weak_self__.alertController addAction:okAction];
                            [__weak_self__ presentViewController:__weak_self__.alertController animated:YES completion:nil];
                            
                        });
                        
                    }
                    
                }];
                
            }else
            {
                dispatch_async(dispatch_get_main_queue(), ^{
                    NSString *errorMessage = resultField.ErrorMsg;
                    __weak_self__.alertController = [UIAlertController alertControllerWithTitle:errorMessage message:nil preferredStyle:UIAlertControllerStyleAlert];
                    
                    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                        
                        [ __weak_self__ tradeNextNumAction];
                        [__weak_self__ dismissViewControllerAnimated:__weak_self__.alertController completion:nil];
                    }];
                    
                    [__weak_self__.alertController addAction:okAction];
                    [__weak_self__ presentViewController:__weak_self__.alertController animated:YES completion:nil];
                    
                });
                
            }
        }];
    }
}
- (void)tradeNextNumAction
{
    weakify(self)
    [[SSWETraderApiWrapper sharedManager] ReqValidateCode:@{} Callback:^(id bizRspInfo, NSDictionary *resultInfo, int requestId, bool isLast, bool isError) {
        
        SSWEOCShfeFtdcRspValidateCodeField *field = (SSWEOCShfeFtdcRspValidateCodeField*)bizRspInfo;
        
        NSString *vcode = field.ValidateCodeQuestion;
        if (vcode != nil) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                [__weak_self__.tradeLoginView.showNumLabel setText:vcode];
            });
            
        } else {
            dispatch_async(dispatch_get_main_queue(), ^{
                
                __weak_self__.alertController = [UIAlertController alertControllerWithTitle:@"没有得到vcode" message:nil preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    [__weak_self__ dismissViewControllerAnimated:__weak_self__.alertController completion:nil];
                }];
                
                [__weak_self__.alertController addAction:okAction];
                [__weak_self__.navigationController presentViewController:__weak_self__.alertController animated:YES completion:nil];
            });
            
        }
        
        
        
    }];
    
    
}
- (void)tradeFogetPwdAction
{
    //    SSWEFoggetPWDViewController  *fogetPWDCtrl = [[SSWEFoggetPWDViewController alloc] init];
    //    [self presentViewController:fogetPWDCtrl animated:YES completion:nil];
    //
}


#pragma mark --- MessageLoginDelegate

- (void)messageLoginActionn
{
    
    
    
}

- (void)messageRegisterActions
{
    
    
    
}

- (void)messageGetVerifyNumAction
{
    
    
    
}


#pragma mark ----getter and setters
- (UIView *)headerView
{
    if (!_headerView) {
        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 150)];
        _headerView.dk_backgroundColorPicker = DKColorPickerWithKey(LOGINBG);
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, SCREEN_WIDTH, 45)];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        //        titleLabel.dk_textColorPicker = DKColorPickerWithKey(TEXT);
        titleLabel.font = [UIFont boldSystemFontOfSize:17.0];
        titleLabel.text = @"上期所标准仓单交易平台交易终端";
        titleLabel.textColor = [UIColor whiteColor];
        [_headerView addSubview:titleLabel];
    }
    return _headerView;
    
}


- (UIView *)bottomView
{
    if (!_bottomView) {
        _bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 30, SCREEN_WIDTH, 30)];
        UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
        lable.text = @"上海期货交易所";
        lable.textAlignment = NSTextAlignmentCenter;
        _bottomView.backgroundColor = [UIColor grayColor];
        lable.font = [UIFont systemFontOfSize:13];
        [_bottomView addSubview:lable];
        
    }
    return _bottomView;
    
}

- (UIButton *)tradeLoginBtn
{
    if (!_tradeLoginBtn) {
        
        _tradeLoginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_tradeLoginBtn setTitle:@"交易/行情登录" forState:UIControlStateNormal];
        _tradeLoginBtn.titleLabel.dk_textColorPicker = DKColorPickerWithKey(TEXT);
        _tradeLoginBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_tradeLoginBtn addTarget:self action:@selector(tradeLoginAction:) forControlEvents:UIControlEventTouchUpInside];
        if (_tradeLoginBtn.selected == YES) {
            [self.arrowLayer removeFromSuperlayer];
            self.arrowLayer.position = CGPointMake(self.tradeLoginBtn.frame.size.width/2, self.tradeLoginBtn.frame.size.height - 3);
            [_tradeLoginBtn.layer addSublayer:self.arrowLayer];
        }
        
    }
    return _tradeLoginBtn;
    
}

- (UILabel *)centerLabel
{
    if (!_centerLabel) {
        _centerLabel = [[UILabel alloc] init];
        _centerLabel.backgroundColor = [UIColor whiteColor];
    }
    return _centerLabel;
}

- (UIButton *)messageLoginBtn
{
    if (!_messageLoginBtn) {
        _messageLoginBtn  = [UIButton buttonWithType:UIButtonTypeCustom];
        [_messageLoginBtn setTitle:@"短信登录" forState:UIControlStateNormal];
        _messageLoginBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];
        [_messageLoginBtn addTarget:self action:@selector(messageLoginAction:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _messageLoginBtn;
    
}

- (UIView *)messageLoginView2
{
    if (!_messageLoginView2) {
        _messageLoginView2 = [[UIView alloc] init];
        
        
        
    }
    return _messageLoginView2;
}

- (MessageLoginView *)messageLoginView
{
    if (!_messageLoginView) {
        
        _messageLoginView = [[NSBundle mainBundle] loadNibNamed:@"MessageLoginView" owner:self options:Nil][0];
        _messageLoginView.tag = 2018042602;
        
        
    }
    return _messageLoginView;
    
}

- (TradeLoginView *)tradeLoginView
{
    if (!_tradeLoginView) {
        
        _tradeLoginView = [[NSBundle mainBundle] loadNibNamed:@"TradeLoginView" owner:self options:nil][0];
        _tradeLoginView.tag = 2018042601;
        _tradeLoginView.delegate = self;
        
    }
    return _tradeLoginView;
    
}

- (void)messageLoginAction:(UIButton *)sender
{
    UIView *tradeView = (UIView *)[self.view viewWithTag:2018042601];
    [tradeView removeFromSuperview];
    self.tradeLoginBtn.selected = NO;
    self.messageLoginBtn.selected = YES;
    [self.arrowLayer removeFromSuperlayer];
    self.arrowLayer.position = CGPointMake(self.messageLoginBtn.frame.size.width/2, self.messageLoginBtn.frame.size.height - 3);
    [self.messageLoginBtn.layer addSublayer:self.arrowLayer];
    
    [self.view addSubview:self.messageLoginView];
    [self.messageLoginView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerView.bottom);
        make.left.mas_equalTo(0);
        make.right.equalTo(SCREEN_WIDTH);
        make.bottom.equalTo(self.bottomView.top);
    }];
}

- (void)tradeLoginAction:(id)sender
{
    UIView *messageView = (UIView *)[self.view viewWithTag:2018042602];
    [messageView removeFromSuperview];
    self.messageLoginBtn.selected = NO;
    self.tradeLoginBtn.selected = YES;
    [self.arrowLayer removeFromSuperlayer];
    self.arrowLayer.position = CGPointMake(self.tradeLoginBtn.frame.size.width/2, self.tradeLoginBtn.frame.size.height - 3);
    [self.tradeLoginBtn.layer addSublayer:self.arrowLayer];
    
    [self.view addSubview:self.tradeLoginView];
    [self.tradeLoginView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerView.bottom);
        make.left.mas_equalTo(0);
        make.right.equalTo(SCREEN_WIDTH);
        make.bottom.equalTo(self.bottomView.top);
    }];
    
}

-(void)dealloc
{
    [SSWE_GLOBAL removeObserver:self forKeyPath:@"TraderFrontConnected"];
    [SSWE_GLOBAL removeObserver:self forKeyPath:@"MdFrontConnected"];
}
@end
